﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Ucb.Workshop.Presenters;
using Ucb.Workshop.Dal;

namespace Ucb.Workshop.WinApp.View.GestionProducto.Views
{
    public partial class RegistroMarcaView : UserControl, IRegistroMarcaView
    {
        private RegistroMarcaPresenter presenter;
        private DBManager manager;

        public RegistroMarcaView()
        {
            InitializeComponent();
            presenter = new RegistroMarcaPresenter(this);
            manager = new DBManager();
            CargarMarcasAlDataGridView();
        }

        private void btnRegistrarMarca_Click(object sender, EventArgs e)
        {
            try
            {
                presenter.OnRegistroMarca();
                CargarMarcasAlDataGridView();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void CargarMarcasAlDataGridView()
        {
            string consulta = "SELECT cod_marca, nombre FROM marca";
            manager.LlenarGrid(gridMarca, consulta);

            gridMarca.Columns[0].Visible = false;
            gridMarca.Columns[1].HeaderText = "Marca";
        }

        #region IRegistroMarcaView Members

        public string Nombre
        {
            get { return txtMarca.Text; }
        }

        #endregion

        private void txtBuscarMarca_TextChanged(object sender, EventArgs e)
        {
            string consulta = "SELECT cod_marca, nombre FROM marca WHERE nombre LIKE '%" + txtBuscarMarca.Text + "%'";
            manager.LlenarGrid(gridMarca, consulta);

            gridMarca.Columns[0].Visible = false;
            gridMarca.Columns[1].HeaderText = "Marca";
        }
    }
}
